package custom

import (
	"encoding/json"
	"gitee.com/alex_li/rodinbell/mq"
	"gitee.com/alex_li/rodinbell/reader"
	"github.com/lishimeng/go-log"
)

func OnData(data reader.TagInfo) {

	go upstream(data)
}

func upstream(data reader.TagInfo) {
	log.Info("upstream: %s", data.EpcText)
	bs, err := json.Marshal(data)
	if err != nil {
		log.Info(err)
		return
	}
	if mq.Session != nil && mq.Usable {
		mq.Session.Publish(bs)
	}
}
